<!-- 容器类型管理 - 综合表单页面 -->
<template>
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" pageOption />

    <ex_super_table_page v-bind="option" ref="SuperTablePage">
    </ex_super_table_page>
    <ex_super_dialog_form ref="formDialog" v-bind="dialog" @afterSubmitSuccess="$refs['SuperTablePage'].reload()">
    </ex_super_dialog_form>

    <el-dialog :visible.sync="visible" title="" destroy-on-close @close="resetForm('dialogFrom')">
      <el-form :model="form" label-widget="80px" ref="dialogFrom">
        <ex_header_spiler :title="$tt(['label_add', 'label_container_stock'])"></ex_header_spiler>
        <el-row>
          <el-col :span="8" prop="number">
            <el-form-item :label="$tt(['label_add', 'label_stock_count'])" prop="number">
              <ex_super_input :min="1" type="input-number" v-model="form.number" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$tt('label_container_Layout_row_count')" prop="row">
              <ex_super_input :min="1" :max="16" type="input-number" v-model="form.row" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$tt('label_container_Layout_col_count')" prop="column">
              <ex_super_input :min="1" :max="16" type="input-number" v-model="form.column" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog_button_footer">
        <el-button @click="resetForm('dialogFrom')">{{ $tt('label_cancel') }}</el-button>
        <el-button type="primary" @click="addStockForm">{{ $tt('label_submit') }}</el-button>

      </div>
    </el-dialog>
    <!-- <DetailContainerType ref="detail_container_type"></DetailContainerType> -->

    <dialog_detail_desc ref="dialog_detail_desc" url="/wms-api/base/WmsBaseContainerTypeRpc/detail.json"
      :descOption="descOption" />
  </div>
</template>
<script>
import superTablePageFunction from '@/mixin/super-table-page-function';
import page_table_model_manage from '@/mixin/page_table_model_manage';

// import DetailContainerType from '../../../component/dialog/wms_base/detail_container_type.vue'
export default {
  title: 'title_container_type_manage',
  mixins: [superTablePageFunction, page_table_model_manage],
  components: {},
  data() {
    return {
      visible: false,
      form: {
        id: '',
        number: 1,
        row: 1,
        column: 1,
      },
      rules: {
        'number': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
        'row': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
        'column': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
      },

      option: {
        search: {
          model: [
            { label: "label_container_type_code", key: "code", type: 'input', },
            {
              label: "label_status", key: "status", type: 'select',//
              items: [{ label: 'label_available', value: 'ENABLE' }, { label: 'label_discard', value: 'DISABLED' }]//
            },
            {
              label: "label_usage", key: "usageType", type: 'select', enum: 'BaseContainerTypeEnum',
            },
            {
              label: "label_start_time",
              key: "createDateStart",
              fold: true,
              type: 'date-picker',
              attrs: { type: "datetime" },
            },
            {
              label: "label_end_time",
              key: "createDateEnd",
              fold: true,
              type: 'date-picker',
              attrs: { type: "datetime" },
            },
          ],
        },
        action: [
          {
            label: ['label_new', 'label_container_type'], attrs: { icon: "el-icon-plus" }, auth: "wms_container_type_edit", click: () => {
              this['$refs']['formDialog'].showNew({
                title: this.$tt(['label_new', 'label_container_type']),
                data: { warehouseId: this.$loginUser.currentWarehouseId },
                onlySetData: true
              })
            }
          },
        ],

        table: {
          url: "/wms-api/base/WmsBaseContainerTypeRpc/selectPage.json",
          attrs: {},
          model: this.init_table_model(),

        },
      },

      dialog: {
        customClass: 'dialog_auto',
        submitUrl: '/wms-api/base/WmsBaseContainerTypeRpc/saveUpdate.json',
        detailUrl: '/wms-api/base/WmsBaseContainerTypeRpc/detail.json',
        form: {
          itemClass: "form_item_default", inputClass: "form_input_default",
          model: [

            { key: 'code', label: 'label_container_type_code', disabled: (data) => !_.isEmpty(data.id) },
            { key: 'name', label: 'label_container_type_name', },

            { key: 'length', label: 'label_length', append: 'cm', appendClass: 'input_slot_div_mini' },
            { key: 'width', label: 'label_width', append: 'cm', appendClass: 'input_slot_div_mini' },
            { key: 'height', label: 'label_height', append: 'cm', appendClass: 'input_slot_div_mini' },
            { key: 'volume', label: 'label_inner_capacity', append: 'm³', appendClass: 'input_slot_div_mini' },
            { key: 'weight', label: 'label_load_capacity', append: 'kg', appendClass: 'input_slot_div_mini' },
            { key: 'usageType', label: 'label_usage', type: 'select', enum: 'BaseContainerTypeEnum' },
          ],
          rules: {
            'code': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'name': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'usage': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },

            'length': {
              required: true, trigger: 'blur',
              validator: (r, v, cb) => this.$ruleStandard({ v, cb, type: 'dimen', required: true, }) ? cb() : null,
            },
            'width': {
              required: true, trigger: 'blur',
              validator: (r, v, cb) => this.$ruleStandard({ v, cb, type: 'dimen', required: true, }) ? cb() : null,
            },
            'height': {
              required: true, trigger: 'blur',
              validator: (r, v, cb) => this.$ruleStandard({ v, cb, type: 'dimen', required: true, }) ? cb() : null,
            },
            'volume': {
              required: true, trigger: 'blur',
              validator: (r, v, cb) => this.$ruleStandard({ v, cb, type: 'volume', required: true, }) ? cb() : null,
            },
            'weight': {
              required: true, trigger: 'blur',
              validator: (r, v, cb) => this.$ruleStandard({ v, cb, type: 'weight', required: true, }) ? cb() : null,
            },
            'usageType': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }
          },
        }
      },
      descOption: {
        model: [
          { key: 'code', label: 'label_container_type_code' },
          { key: 'name', label: 'label_container_type_name' },
          { key: 'warehouseCode', label: 'label_warehouse_code' },
          { key: 'status', label: 'label_status', formatter: (r, c, v) => this.$enumShow(v, "IsAvailableStatusEnum") },

          { key: 'usageType', label: 'label_usage', formatter: (r, c, v) => this.$enumShow(v, "BaseContainerTypeEnum") },
          { key: 'length', label: 'label_length', formatter: (r, c, v, i) => `${v}cm` },
          { key: 'width', label: 'label_width', formatter: (r, c, v, i) => `${v}cm` },
          { key: 'height', label: 'label_height', formatter: (r, c, v, i) => `${v}cm` },
          { key: 'volume', label: 'label_capacity', formatter: (r, c, v, i) => `${v}m³` },
          { key: 'weight', label: 'label_load_capacity', formatter: (r, c, v, i) => `${v}kg` },

          { key: 'useQty', label: 'label_used_count' },
          { key: 'freeQty', label: 'label_idle_count' },
          { key: 'unableQty', label: 'label_disabled_count' },
          { key: 'totalQty', label: 'label_sum' },

          { key: 'creator', label: 'label_create_user', },
          { key: 'gmtCreate', label: 'label_create_time', formatter: (r, c, v, i) => this.$dateFormat(v) }

        ],
      },
    };
  },
  methods: {
    option_table_model() {
      return [
        { key: 'warehouseCode', label: 'label_warehouse_code', },
        { key: 'code', label: 'label_container_type_code', },
        { key: 'status', label: 'label_status', formatter: (r, c, v, i) => this.$enumShow(v, "IsAvailableStatusEnum") },
        { key: 'name', label: 'label_container_type_name', },
        { key: 'length', label: 'label_length', formatter: (r, c, v, i) => this.$addUnit(this.$formatDigit(v), 'cm') },
        { key: 'width', label: 'label_width', formatter: (r, c, v, i) => this.$addUnit(this.$formatDigit(v), 'cm') },
        { key: 'height', label: 'label_height', formatter: (r, c, v, i) => this.$addUnit(this.$formatDigit(v), 'cm') },
        { key: 'volume', label: 'label_inner_capacity', formatter: (r, c, v, i) => this.$addUnit(this.$formatDigit(v), 'm³') },
        { key: 'weight', label: 'label_load_capacity', formatter: (r, c, v, i) => this.$addUnit(this.$formatDigit(v), 'kg') },
        { key: 'usageType', label: 'label_usage', formatter: (r, c, v, i) => this.$enumShow(v, "BaseContainerTypeEnum") },
        { key: 'useQty', label: 'label_used_count', },
        { key: 'freeQty', label: 'label_idle_count', },
        { key: 'unableQty', label: 'label_disabled_count', },
        { key: 'totalQty', label: 'label_sum', },
        { key: 'gmtCreate', label: 'label_create_time', 'min-width': 130, formatter: (r, c, v, i) => this.$dateFormat(v) },
        {
          type: 'operate', width: 230, fixed: 'right', operate: [
            {
              label: 'label_edit', auth: "wms_container_type_edit", click: (row) => {
                this['$refs']['formDialog'].showNew({
                  title: this.$tt(['label_edit', 'label_container_type']),
                  params: { "id": row["id"] },
                })
              }
            },
            { label: 'label_add_stock', auth: 'wms_container_type_add_stock', click: (row) => { this.checkStock(row) } },
            { label: 'label_view_detail', click: (row) => { this.clickDetail(row) } },
            {
              label: 'label_delete', auth: "wms_container_type_delete", type: "confirm-button", url: '/wms-api/base/WmsBaseContainerTypeRpc/remove.json', message: '确定要删除该记录吗？',
              params: (row) => { return { "id": row["id"] } }, done: ['reload', 'tip']
            },
          ]
        },
      ]
    },
    clickDetail(row) {
      let title = this.$formatNameCode(this.$tt('label_container_type_detial'), row.code)
      this.$refs['dialog_detail_desc'].show({ params: { id: row.id }, title })
      // this.$refs['detail_container_type'].show({ params: { id: row.id }, title })
    },
    checkStock(row) {
      this.form.id = row.id
      this.visible = true
    },

    addStockForm() {
      let comparentNum = this.form.row * this.form.column
      if (comparentNum > 16) {
        this.$message.error(this.$tt('tip_grid_rows_col_cannot_greater_16'));
        return
      }

      let data = this.form

      this.$ajax({
        url: '/wms-api/base/WmsBaseContainerTypeRpc/addStock.json',
        type: 'json',
        data,
        success: (responseData) => {
          this.$message({
            type: 'success',
            message: this.$tt('tip_operate_success')
          })
          // this.$emit('afterSubmitSuccess', this.$refs.form.getData())
          this.visible = false
        },
        complete: () => {
          this.submiting = false
        }

      });
    },
    resetForm(formName) {
      this.visible = false
      this.$refs[formName].resetFields();
    },
  }
};

</script>
<style></style>
